package top.xbaoziplus.company.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @author xBaozi
 * @version 1.0
 * @classname GlobalExceptionHandle
 * @description 全局异常处理器
 * @date 2022/4/28 18:29
 */
@ControllerAdvice(annotations = {RestController.class, Controller.class})
@ResponseBody
@Slf4j
public class GlobalExceptionHandle {

    /**
     * @description 异常处理方法，处理自定义业务异常
     * @author xBaozi
     * @date 18:32 2022/4/28
     **/
    @ExceptionHandler(CustomException.class)
    public Result<String> exceptionHandle(CustomException e) {
        log.info(e.getMessage());
        return Result.fail(e.getMessage());
    }
}
